#include <stdio.h>
// LRU
int main()
{
    int cook[3] = {};   // 灶台
    int n, time = 0;
    while(1){
        scanf("%d", &n);
        if(n == 7) break;
        int exist = 0;
        for(int i = 0; i < 3; ++i){
            if(cook[i] == n){
                exist = 1;
                break;
            }
        }
        time += 15;
        // 更换厨具
        if(exist == 0) time += 6;
        for(int i = 2; i > 0; --i){
            if(cook[i-1] != n) 
                cook[i] = cook[i-1];
        }
        cook[0] = n;  // 更新灶台
    } 
    time -= 18;   // 减去前3次
    printf("%d\n", time);
    return 0;
}